package com.njust.vo;

import java.io.Serializable;

import com.njust.enums.RespCode;

/**
 * Created by zhujiawei on 2017/12/28.
 */

public class ResultVO<T> implements Serializable {

    private static final long serialVersionUID = -5686033574197482732L;

    //返回给前端的数据
    private T data;
    /**
     * code 表示错误码 默认0表示正常
     */
    private int code;
    /**
     提示信息
     */
    private String msg;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public ResultVO() {
    }

    private  ResultVO(int code){
        this.code=code;
    }
    private  ResultVO(int code,T data){
        this.code=code;
        this.data=data;
    }

    private  ResultVO(int code,String msg){
        this.code=code;
        this.msg=msg;
    }
    private  ResultVO(int code,T data,String msg){
        this.code=code;
        this.data=data;
        this.msg=msg;
    }

    public static <T> ResultVO<T> createBySuccess(){
        return new ResultVO<T>(RespCode.SUCCESS.getCode());
    }

    public  static <T> ResultVO<T> createBySuccessMessage(String msg){
        return new ResultVO<T>(RespCode.SUCCESS.getCode(),msg);
    }

    public  static <T> ResultVO<T> createBySuccess(T data){
        return new ResultVO<T>(RespCode.SUCCESS.getCode(),data);
    }

    public  static <T> ResultVO<T> createBySuccess(String msg,T data){
        return new ResultVO<T>(RespCode.SUCCESS.getCode(),data,msg);
    }

    public static <T> ResultVO<T> createByError(){
        return new ResultVO<T>(RespCode.ERROR.getCode(),RespCode.ERROR.getMsg());
    }


    public static <T> ResultVO<T> createByErrorMessage(String errorMessage){
        return new ResultVO<T>(RespCode.ERROR.getCode(),errorMessage);
    }

    public static <T> ResultVO<T> createByErrorCodeMessage(int errorCode,String errorMessage){
        return new ResultVO<T>(errorCode,errorMessage);
    }
}
